package com.example.bailin.giftsay.guide.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.bailin.giftsay.R;
import com.example.bailin.giftsay.tool.MyApp;

/**
 * Created by bailin on 16/8/22.
 */
public class DotAdapter extends RecyclerView.Adapter<DotAdapter.DotViewHolder> {
    private int count;
    private int index;

    public void setIndex(int index) {
        this.index = index;
        notifyDataSetChanged();
    }

    public void setCount(int count) {
        this.count = count;
        notifyDataSetChanged();
    }

    @Override
    public DotViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(MyApp.getContext()).inflate(R.layout.item_dot, parent, false);
        DotViewHolder viewHolder = new DotViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(DotViewHolder holder, int position) {
        if (count % index == position) {
            holder.iv.setBackgroundResource(R.drawable.dot_focused);
        } else {
            holder.iv.setBackgroundResource(R.drawable.dot_normal);
        }

    }

    @Override
    public int getItemCount() {
        return index;
    }

    public class DotViewHolder extends RecyclerView.ViewHolder {
        ImageView iv;
        public DotViewHolder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.iv_dot_id);
        }
    }
}
